<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

function get_default_category($parent_id=0){
    $CI =&get_instance();
    $CI->load->model('category');
    
    $cat_id = $CI->db->select('id')
            ->from('es_category')
            ->where('id_parent',$parent_id)
            ->limit(1)
            ->get()->row()->id;
    return $cat_id;
}
function get_parent_category_id($id){
    $CI =&get_instance();
    $CI->load->model('category');
    
    $cat_id = $CI->db->select('id_parent')
            ->from('es_category')
            ->where('id',$id)
            ->get()->row()->id_parent;
    return $cat_id;
}
function generate_depth($id){
    $CI =&get_instance();
    $CI->load->model('category');
    $parent_id = get_parent_category_id($id);
    return $CI->db->select('level_depth')
            ->from('es_category')
            ->where('id',$parent_id)
            ->get()->row()->level_depth+1;
}